/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code3 {
    // 对称二叉树迭代版
    public boolean isSymmetric(TreeNode root) {
        Queue<TreeNode> q = new LinkedList<>();

        q.offer(root);
        q.offer(root);

        while(!q.isEmpty()) {
            int sz = q.size();

            TreeNode l = q.poll();
            TreeNode r = q.poll();
            if(l==null && r==null) {
                continue;
            } else if(l==null || r==null){
                return false;
            } else if(l.val != r.val) {
                return false;
            }

            q.offer(l.left);
            q.offer(r.right);

            q.offer(l.right);
            q.offer(r.left);
        }
        return true;
    }
}